﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Xyz.BusinessObjects;
using Xyz.DataObjects.Interfaces;

namespace Xyz.DataObjects.Entity.Dao
{
    public class EntityServiceDao : IServiceDao
    {

            public List<Service> GetAllServices()
            {
                using (var context = EntityObjectFactory.CreateContext())
                {
                    var services = new List<Service>();
                    var query = context.ServiceEntities.AsQueryable().ToList();

                    query.ForEach(x => services.Add(Mapper.Map(x)));

                    return services;
                }

            }
            public List<Service> GetAllServicesByServiceCategoryCode(string serviceCategoryCode)
            {
                using (var context = EntityObjectFactory.CreateContext())
                {
                   
                    var services = new List<Service>();
                   
                    var query = context.ServiceEntities.Where(x => x.ServiceCategoryCode == serviceCategoryCode).AsQueryable().ToList();

                    query.ForEach(x => services.Add(Mapper.Map(x)));

                    return services;
                }
            }

            public Service GetServiceByServiceCode(string serviceCode)
            {

                using (var context = EntityObjectFactory.CreateContext())
                {

                    var service = context.ServiceEntities.SingleOrDefault(x => x.ServiceCode == serviceCode);


                    if (service != null)
                    {

                        return (Mapper.Map(service));
                    }

                    return null;

                }
            }
        
    }
}
